package com.sqsf.util;

import com.sqsf.javabean.Role;
import mapper.RoleMapper;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import java.util.List;

public class RoleMapperTest {
    SqlSession session;
    RoleMapper mapper;

    @Before
    public void before() {

        SqlSessionFactory factory = MyBatisUtil.getSqlSessionFactory();

        session = factory.openSession(true);

        mapper = session.getMapper(RoleMapper.class);

    }

    @After
    public void after() {

        session.close();
    }

    @Test
    public void selectRole_Permission(){
        for (Role role : mapper.selectRole_Permission()) {
            System.out.println(role);
        }
    }

    @Test
    public void selectRole_Permission_lazy(){
        List<Role> roles = mapper.selectRole_Permission_lazy();

        Role role = roles.get(1);
        System.out.println(role.getRid());
        System.out.println(role.getName());
        System.out.println(role.getDesc());
        System.out.println("~~~~~~~~~~~~~~~~~~~~");

        System.out.println(role.getPlist());
    }
}